#

| Chapter 28 Comparing Files |

## 28.4 Side-by-Side diffs: sdiff

sdiff | After you've used diff for a while, the output is easy to read. Sometimes, though, it's just easier to see two files side-by-side. The sdiff command does that. (There's also a GNU version on the CD-ROM.) Between the files, it prints `<` to point to lines that are only in the first file, `>` for lines only in the second file, and `|` for lines that are in both, but different. By default, sdiff shows all the lines in both files. Here's a fairly bogus example that compares two files that contain the output of who (51.4) at different times:

>     $ sdiff -w75 who1 who2
>     jake     vt01      Sep 10 10:37      jake     vt01      Sep 10 10:37
>     uunmv    ttyi1i    Sep 16 11:43   <
>     jerry    ttyi1j    Sep 15 22:38      jerry    ttyi1j    Sep 15 22:38
>     jake     ttyp1     Sep  9 14:55      jake     ttyp1     Sep  9 14:55
>     jake     ttyp2     Sep  9 15:19   |  ellen    ttyp2     Sep 16 12:07
>                                       >  carolo   ttyp5     Sep 16 13:03
>     alison   ttyp8     Sep  9 12:49      alison   ttyp8     Sep  9 12:49

To see only lines that are different, use -s (silent):

>     $ sdiff -s -w75 who1 who2
>     2d1
>     uunmv    ttyi1i    Sep 16 11:43   <
>     5c4,5
>     jake     ttyp2     Sep  9 15:19   |  ellen    ttyp2     Sep 16 12:07
>                                       >  carolo   ttyp5     Sep 16 13:03

The output lines are usually 130 characters long. That's too long for 80-column-wide screens; if you can put your terminal in 132-column mode or stretch your window, fine. If you can't, use the -w option to set a narrower width, like -w80 for 80-column lines; sdiff will show the first 37 characters from each line (it doesn't write quite all 80 columns). If you can set your printer to compressed type or have a very wide window, use an option like -w170 to get all of each line.

Article 28.6 explains a very useful feature of sdiff: building one file interactively from two files you compare.

- JP

28.3 Context diffs |  | 28.5 Comparing Files Alongside One Another